package com.example.demo.service.impl;

import com.example.demo.bean.Goods;
import com.example.demo.bean.ShoppingCart;
import com.example.demo.bean.User;
import com.example.demo.bean.view.ShoppingCartView;
import com.example.demo.mapper.ShoppingCartMapper;
import com.example.demo.service.OrderService;
import com.example.demo.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("ShoppingCartService")
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Autowired(required=true)
    @Qualifier("ShoppingCartMapper")
    private ShoppingCartMapper shoppingCartMapper;

    //插入购物车
    @Override
    public boolean insertShoppingCart(ShoppingCart shoppingCart) {
        return shoppingCartMapper.insertShoppingCart(shoppingCart.getShoppingCartNum(), shoppingCart.getBuyerNum(), shoppingCart.getGoodsNum(), shoppingCart.getNumOfGoods(), shoppingCart.getBelong());
    }

    @Override
    public boolean deleteShoppingCart(ShoppingCart shoppingCart) {

        return shoppingCartMapper.deleteShoppingCart(shoppingCart.getShoppingCartNum());
    }

    //修改购物车内商品数量
    @Override
    public boolean updateShoppingCart(ShoppingCart preShoppingCart, ShoppingCart laShoppingCart) {
        return shoppingCartMapper.updateShoppingCart(preShoppingCart.getShoppingCartNum(), laShoppingCart.getNumOfGoods());
    }

    @Override
    public List<ShoppingCart> findAllShoppingCart() {
        if(shoppingCartMapper.findAllShoppingCart() != null)
        {
            return shoppingCartMapper.findAllShoppingCart();
        }
        else
        {
            return null;
        }
    }

    @Override
    public List<ShoppingCartView> findShoppingCartByBuyerNum(User buyer) {
        List<ShoppingCartView> shoppingCartViewList = shoppingCartMapper.findShoppingCartByBuyerNum(buyer.getUserNum());
        if(shoppingCartViewList != null)
        {
            return shoppingCartViewList;
        }
        else{
            return null;

        }

    }

    @Override
    public List<ShoppingCartView> findShoppingCartView() {
        List<ShoppingCartView> shoppingCartViewList = shoppingCartMapper.findAllShoppingCartView();

        if(shoppingCartViewList != null)
            return shoppingCartViewList;
        else
            return null;
    }


}
